package com.jlf.core.engine.builder;

import com.jlf.core.engine.builder.db.AutoMysqlSqlTableBuilder;
import com.jlf.core.engine.builder.db.AutoOracleSqlTableBuilder;
import com.jlf.core.engine.builder.db.AutoPgSqlTableBuilder;
import com.jlf.core.engine.domain.SchemaCriterionDO;
import com.jlf.core.engine.domain.SchemaDomainDO;
import com.jlf.core.engine.domain.SchemaFieldDO;
import com.jlf.core.engine.domain.SchemaIndexDO;
import com.jlf.core.engine.meta.MetaRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 生成自动建表、更新表的语句
 *
 * @author wujr
 * 2023/7/14
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/14 1.0 新增]
 */
@Slf4j
@RequiredArgsConstructor
public class AutoSqlTableBuilder {
    private final MetaRepository metaRepository;
    private final SchemaDomainDO schemaDomain;
    private final List<SchemaFieldDO> schemaFields;
    private final List<SchemaIndexDO> schemaIndexes;

    /**
     * 生成建表语句和注释语句
     * @return 建表语句和注释语句
     */
    public List<String> generate(){
        if (metaRepository.isPostgresql()){
            return AutoPgSqlTableBuilder.generate(schemaDomain, schemaFields, schemaIndexes);
        }else if (metaRepository.isMySql()){
            return AutoMysqlSqlTableBuilder.generate(schemaDomain, schemaFields, schemaIndexes);
        }else if (metaRepository.isOracle()){
            return AutoOracleSqlTableBuilder.generate(schemaDomain, schemaFields, schemaIndexes);
        }else{
            throw new RuntimeException("不支持的数据库");
        }
    }
}
